home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 3 of 3.iso / chapte10 / getid / line.c < prev    next >
C/C++ Source or Header  |  1996-04-28  |  25KB  |  769 lines

  1.  
  2. #include <windows.h> 
  3. #include <windowsx.h> 
  4. #include "line.h" 
  5. #include "tapi.h"
  6.  
  7. #define BUFSIZE 256
  8. #define APIHIVERSION     0x00010028    /* 1.40 */
  9. #define APILOWVERSION    0x00010000    /* 1.0 */
  10. #define EXTHIVERSION     0x00010005    /* 1.5 */
  11. #define EXTLOWVERSION    0x00000009    /* 0.9 */ 
  12. #define OWNER        0
  13. #define MONITOR      1
  14. #define MAX_CALL        3
  15. #define MAX_LINE        2
  16.  
  17.  
  18. #if defined (WIN32)
  19.     #define IS_WIN32 TRUE
  20. #else
  21.     #define IS_WIN32 FALSE
  22. #endif
  23.  
  24. #define IS_NT      IS_WIN32 && (BOOL)(GetVersion() < 0x80000000)
  25. #define IS_WIN32S  IS_WIN32 && (BOOL)(!(IS_NT) && (LOBYTE(LOWORD(GetVersion()))<4))
  26. #define IS_WIN95   (BOOL)(!(IS_NT) && !(IS_WIN32S)) && IS_WIN32
  27.  
  28. LPCTSTR lpszAppName = "lineGetID";
  29. LPCTSTR lpszTitle   = "lineGetID"; 
  30.  
  31. HINSTANCE hInst;   // current instance
  32. HWND hWnd;         // parent window handle
  33. HWND hListWnd;     // listbox
  34. HDC  hdc;
  35. TEXTMETRIC  tm ;
  36.  
  37. BOOL RegisterWin95( CONST WNDCLASS* lpwc );
  38.  
  39.  
  40. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  41.                       LPTSTR lpCmdLine, int nCmdShow)
  42. {
  43.    MSG      msg;
  44.    WNDCLASS wc;
  45.  
  46.    wc.style         = CS_HREDRAW | CS_VREDRAW;
  47.    wc.lpfnWndProc   = (WNDPROC)WndProc;       
  48.    wc.cbClsExtra    = 0;                      
  49.    wc.cbWndExtra    = 0;                      
  50.    wc.hInstance     = hInstance;              
  51.    wc.hIcon         = LoadIcon (hInstance, lpszAppName); 
  52.    wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  53.    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
  54.    wc.lpszMenuName  = lpszAppName;              
  55.    wc.lpszClassName = lpszAppName;              
  56.  
  57.    if ( IS_WIN95 )
  58.    {
  59.       if ( !RegisterWin95( &wc ) )
  60.          return( FALSE );
  61.    }
  62.    else if ( !RegisterClass( &wc ) )
  63.       return( FALSE );
  64.  
  65.    hInst = hInstance; 
  66.  
  67.    hWnd = CreateWindow( lpszAppName, 
  68.                         lpszTitle,    
  69.                         WS_OVERLAPPEDWINDOW, 
  70.                         CW_USEDEFAULT, 0, 
  71.                         CW_USEDEFAULT, 0,  
  72.                         NULL,              
  73.                         NULL,              
  74.                         hInstance,         
  75.                         NULL               
  76.                       );
  77.  
  78.    if ( !hWnd ) 
  79.       return( FALSE );
  80.  
  81.    ShowWindow( hWnd, nCmdShow ); 
  82.    UpdateWindow( hWnd );         
  83.  
  84.    while( GetMessage( &msg, NULL, 0, 0) )   
  85.    {
  86.       TranslateMessage( &msg ); 
  87.       DispatchMessage( &msg );  
  88.    }
  89.  
  90.    return( msg.wParam ); 
  91. }
  92.  
  93.  
  94. BOOL RegisterWin95( CONST WNDCLASS* lpwc )
  95. {
  96.     WNDCLASSEX wcex;
  97.  
  98.    wcex.style         = lpwc->style;
  99.    wcex.lpfnWndProc   = lpwc->lpfnWndProc;
  100.    wcex.cbClsExtra    = lpwc->cbClsExtra;
  101.    wcex.cbWndExtra    = lpwc->cbWndExtra;
  102.    wcex.hInstance     = lpwc->hInstance;
  103.    wcex.hIcon         = lpwc->hIcon;
  104.    wcex.hCursor       = lpwc->hCursor;
  105.    wcex.hbrBackground = lpwc->hbrBackground;
  106.    wcex.lpszMenuName  = lpwc->lpszMenuName;
  107.    wcex.lpszClassName = lpwc->lpszClassName;
  108.  
  109.    // Added elements for Windows 95.
  110.    //...............................
  111.    wcex.cbSize = sizeof(WNDCLASSEX);
  112.    wcex.hIconSm = LoadImage(wcex.hInstance, lpwc->lpszClassName, 
  113.                             IMAGE_ICON, 16, 16,
  114.                             LR_DEFAULTCOLOR );
  115.             
  116.    return RegisterClassEx( &wcex );
  117. }
  118.  
  119. #define CONFCALL    1
  120. #define CONSULT      2
  121.  
  122. enum CallState
  123. {
  124.     Idle,
  125.     Offering,
  126.     Accepted,
  127.     Dialtone,
  128.     Dialing,
  129.     Ringback,
  130.     Busy,
  131.     Special,
  132.     Connected,
  133.     Proceeding,
  134.     Conferenced,
  135.     Onholdconf,
  136.     Disconnected,
  137.     Unknown
  138. };
  139.  
  140. typedef struct tagMYINFO      // general application information
  141. {
  142.     HLINEAPP lineApp;         // instance handle TAPI gives back to us                                                                              through lineInitialize()
  143.     DWORD dwNumDevices;       // number of available devices
  144.     DWORD dwAPIVersion;       // API version the line supports
  145.      DWORD dwExtVersion;           // extended version
  146.     char szLocation[128];     // location        
  147.      char szCallingCard[128];  // calling card being used
  148.     char szAreaCode[4];       // area code       
  149.     char szCountry[128];      // calling card being used
  150. } MYINFO;
  151.  
  152. typedef struct tagLINEINFO  // information on an open line
  153. {
  154.     DWORD dwNumAddress;     // number of available addresses on the line 
  155.     HLINE hLine;            // handle to the line as returned by lineOpen 
  156.      DWORD dwLineID;         // the line ID of this line
  157.     char  szLineName[128];  // the line's name 
  158.  
  159. } MYLINEINFO;
  160.  
  161. typedef struct tagMYCALLINFO  //information on a call                     
  162. {
  163.     
  164. DWORD       eCallState;    // TAPI's line call State, set as user-defined enums
  165. DWORD      dwRequestID;   // requestID returned by async TAPI functions lineMakeCall/lineDropCall
  166. DWORD      dwAddressID;   // the originating address ID of the call being made 
  167. LPCSTR     lpszAddress;    
  168. HLINE     hLine;         // handle to the line 
  169. HCALL        hCall;         // handle to the call 
  170.    
  171. char szDialString[TAPIMAXDESTADDRESSSIZE];  //phone number being dialed
  172. char szDialStringOriginal[TAPIMAXDESTADDRESSSIZE];
  173. char szDialStringCanonical[TAPIMAXDESTADDRESSSIZE];
  174. char szCalledParty[TAPIMAXCALLEDPARTYSIZE]; // name of the party
  175. DWORD dwTranslateResults;
  176.         
  177. } MYCALLINFO;
  178.  
  179. enum CallAction     // Declare enum type CallAction (used in lineSetAppSpecific)
  180. {
  181.    HOLD,            // hold the call
  182.    TRANSFER,        // transfer the call
  183.    REDIRECT,        // redirect the call
  184.    DROP,            // drop the call
  185.    PARK             // park the call
  186. }; 
  187.  
  188. MYINFO myInfo;          //instance of MYINFO structure
  189. MYLINEINFO myLineInfo[MAX_LINE];  //instance of MYLINEINFO structure
  190. MYCALLINFO myCallInfo[MAX_CALL]; //array of MYCALLINFO strcuture
  191.  
  192. LONG lRet;        //return code
  193. char buf[BUFSIZE];    // buffer for debug message
  194.  
  195. DWORD dwLineID = 0;
  196. DWORD i;
  197. LINEEXTENSIONID        ext_id;
  198. LINEDEVCAPS            *plineDevCaps;
  199. LINEADDRESSCAPS        *plineAddressCaps;
  200. LINEADDRESSSTATUS     *plineAddressStat;
  201. LINECALLINFO            *plineCallInfo;
  202. LINECALLSTATUS         *plineCallStatus;
  203. LINECALLLIST            *plineCallList;
  204. LINEDEVSTATUS           *plineDevStatus;
  205. LINETRANSLATECAPS       *plineTranslateCaps;
  206. LINETRANSLATEOUTPUT  *plineTranslateOutput;
  207. LINECALLPARAMS           *plineCallParams;
  208. LINEDEVSTATUS           *plineDevStatus;
  209. LINEFORWARDLIST        *plineForwardList;
  210. LINETRANSLATECAPS       *plineTranslateCaps;
  211. LINEREQMAKECALL       lineReqMakeCall;
  212. VARSTRING               *pDeviceConfig;
  213. VARSTRING               *pDeviceId;
  214. VARSTRING               *pNonDirAddress;
  215.  
  216. LPLINELOCATIONENTRY  lineLocEntry;
  217. LPLINECARDENTRY        lineCardEntry;
  218. LINECOUNTRYLIST         *plineCountryList;
  219. LPLINECOUNTRYENTRY   lineCE;
  220.  
  221. LPSTR                lpData;
  222.  
  223. HICON                hIcon = NULL;        //used in lineGetID();
  224. DWORD                dwNumRings;    //used in lineGetNumRings();
  225. HCALL                hConsultCall; //handle to consultation linePrepareAddToConference, SetupConference
  226. HCALL                hConfCall; //handle to consultation linePrepareAddToConference, SetupConference   
  227. HCALL                hParkedCall;
  228.  
  229. DWORD                dwCompletionID;  //used in lineCompleteCall()
  230.  
  231. char                szName[128];
  232. char                szNumber[128];
  233. char                szDigits[128];
  234. char                szDevConfig[128];
  235.  
  236. LONG lRet;
  237. char buf[BUFSIZE];
  238.  
  239. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  240. {
  241.    switch( uMsg )
  242.    {
  243.       case WM_COMMAND :
  244.          switch( LOWORD( wParam ) )
  245.          {
  246.              case IDM_RUN :
  247.                //allocate buffer for the VARSTRING structure
  248.                //...................................................
  249.                pDeviceConfig = (VARSTRING*) calloc (1,sizeof(VARSTRING)+1000);
  250.                pDeviceConfig->dwTotalSize = sizeof(VARSTRING) + 1000;
  251.             
  252.                // get ID
  253.                //..................................
  254.                lRet = lineGetID(myLineInfo[0].hLine,myCallInfo[0].dwAddressID,   
  255.                       myCallInfo[0].hCall, LINECALLSELECT_LINE, pDeviceConfig, 
  256.                       "tapi/line");
  257.                
  258.                if (lRet == 0)
  259.                {
  260.                   wsprintf (buf, "lineGetID succeeded!");
  261.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  262.                   strcpy(buf, ((LPSTR)(pDeviceConfig)+pDeviceConfig->dwStringOffset));
  263.                   strcat( buf, " is the ID for this line." );
  264.                   SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  265.                }
  266.                else 
  267.                {
  268.                   wsprintf ( buf,"lineGetID failed, err=x%lx", lRet);
  269.                   lineError(lRet);
  270.                }
  271.             
  272.                break;                
  273.  
  274.             case IDM_ABOUT :
  275.             {
  276.                 DialogBox( hInst, "AboutBox", hWnd, (DLGPROC)About );
  277.                break;
  278.             }
  279.  
  280.             case IDM_EXIT :
  281.             {
  282.                for (i = 0; i < myInfo.dwNumDevices; i++)
  283.                        lineClose(myLineInfo[i].hLine);
  284.                     lineShutdown(myInfo.lineApp);
  285.                DestroyWindow( hWnd );
  286.                break;
  287.             }
  288.             }                  
  289.                  
  290.          break;
  291.  
  292.       case WM_CREATE :
  293.       {
  294.          hdc = GetDC (hWnd) ;
  295.          GetTextMetrics (hdc, &tm) ;
  296.          ReleaseDC (hWnd, hdc) ;
  297.  
  298.          hListWnd = CreateWindowEx( 0, "listbox", 
  299.                         " ",    
  300.                         WS_CHILD | WS_VISIBLE,  
  301.                         tm.tmAveCharWidth, tm.tmHeight * 3, 
  302.                         tm.tmAveCharWidth * 16 +
  303.                                    GetSystemMetrics (SM_CXVSCROLL), 
  304.                         tm.tmHeight * 5,  
  305.                         hWnd,              
  306.                         NULL,              
  307.                         hInst,         
  308.                         NULL               
  309.                         );
  310.  
  311.          
  312.          //lineInitialize
  313.             //...............................................
  314.          lRet = lineInitialize(&myInfo.lineApp, hInst, lineCallback, NULL, &myInfo.dwNumDevices);
  315.          if (lRet == 0) 
  316.          {
  317.             wsprintf (buf, "lineInitialize suceeded!");
  318.               SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  319.            }
  320.          else 
  321.           {
  322.                wsprintf ( buf,"lineInitialize failed, err=x%lx",lRet);
  323.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  324.                lineError(lRet);
  325.                break;
  326.          }                    
  327.          
  328.          //lineNegotiateAPIVersion
  329.           //...............................................
  330.          lRet = lineNegotiateAPIVersion(myInfo.lineApp, 0, APILOWVERSION, APIHIVERSION, 
  331.                                            &myInfo.dwAPIVersion, &ext_id);
  332.          if (lRet == 0)                        
  333.          {
  334.             wsprintf (buf, "lineNegotiateAPIVersion suceeded!");
  335.               SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  336.          }
  337.          else 
  338.           {
  339.                wsprintf (buf, "lineNegotiateAPIVersion failed, err=x%lx",
  340.                            lRet);
  341.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  342.                lineError(lRet);
  343.                lineShutdown (myInfo.lineApp);
  344.             break;
  345.          }
  346.  
  347.           //lineNegotiateExtVersion
  348.           //...............................................
  349.          lRet = lineNegotiateExtVersion(myInfo.lineApp, 0, myInfo.dwAPIVersion, EXTLOWVERSION, 
  350.                                            EXTHIVERSION, &myInfo.dwExtVersion);
  351.          if (lRet == 0)                        
  352.          {
  353.             wsprintf (buf, "lineNegotiateExtVersion suceeded!");
  354.             SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  355.  
  356.          }
  357.           else 
  358.           {
  359.                wsprintf (buf, "lineNegotiateExtVersion failed, err=x%lx",
  360.                      lRet);
  361.               SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  362.               lineError(lRet);
  363.       
  364.          }
  365.  
  366.           //lineGetDevCaps
  367.           //for each line device, get capabilities until we find one that supports
  368.          //interactive voice 
  369.           //...............................................
  370.          plineDevCaps = (LINEDEVCAPS *) calloc (1, sizeof(LINEDEVCAPS)+1000);
  371.          plineDevCaps->dwTotalSize = sizeof(LINEDEVCAPS) + 1000;
  372.          for (i = 0; i < myInfo.dwNumDevices; i++)
  373.          {
  374.             lineGetDevCaps(myInfo.lineApp, i, myInfo.dwAPIVersion, 0, plineDevCaps);
  375.             if (plineDevCaps->dwMediaModes & LINEMEDIAMODE_INTERACTIVEVOICE) 
  376.             {
  377.                
  378.                myLineInfo[i].dwNumAddress = plineDevCaps->dwNumAddresses;
  379.                   myLineInfo[i].dwLineID = i;
  380.                    if (plineDevCaps->dwLineNameSize > 0)
  381.                           strcpy(myLineInfo[i].szLineName,((LPSTR)(plineDevCaps)+plineDevCaps->dwLineNameOffset));
  382.              }
  383.           }
  384.  
  385.          //lineOpen
  386.           //................................................................
  387.           lRet = lineOpen(myInfo.lineApp,myLineInfo[OWNER].dwLineID,&myLineInfo[OWNER].hLine,
  388.                            myInfo.dwAPIVersion,0,(DWORD)lineCallback, LINECALLPRIVILEGE_NONE,
  389.                             LINEMEDIAMODE_DATAMODEM, NULL);
  390.           if (lRet == 0)
  391.           {
  392.             wsprintf (buf, "lineOpen suceeded!");
  393.             SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;         }
  394.            else 
  395.            {
  396.                wsprintf ( buf,"lineOpen failed, err=x%lx", lRet);
  397.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;
  398.                lineError(lRet);
  399.           }
  400.        
  401.          break;
  402.       }
  403.       
  404.       case WM_SIZE:
  405.           MoveWindow(hListWnd,0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
  406.          break;
  407.  
  408.       case WM_DESTROY :
  409.               PostQuitMessage(0);
  410.               break;
  411.  
  412.       default :
  413.             return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  414.    }
  415.  
  416.    return( 0L );
  417. }
  418.  
  419.  
  420.  
  421.  
  422. /****************************************************************************
  423.     FUNCTION: lineCallback
  424.     PURPOSE:  callback function handles line events
  425. ****************************************************************************/
  426. LRESULT CALLBACK lineCallback (DWORD dwDevice, DWORD dwMsg,
  427.                                        DWORD dwCallbackInst, DWORD dwParam1,
  428.                                        DWORD dwParam2,DWORD dwParam3)
  429. {
  430.    switch (dwMsg)
  431.    {
  432.       case LINE_CALLSTATE:
  433.        {
  434.             for (i = 0; i < MAX_CALL; i++)
  435.            {
  436.                 if (dwDevice = (DWORD) myCallInfo[i].hCall) 
  437.                  switch (dwParam1)
  438.                  {
  439.                     case LINECALLSTATE_IDLE:
  440.                         myCallInfo[i].eCallState = Idle;
  441.                   break;
  442.                     
  443.                     case LINECALLSTATE_OFFERING:
  444.                   myCallInfo[i].eCallState = Offering;
  445.                   break;
  446.                                    
  447.                     case LINECALLSTATE_ACCEPTED:
  448.                         myCallInfo[i].eCallState = Accepted;
  449.                         break;
  450.                     
  451.                     case LINECALLSTATE_DIALTONE:
  452.                         myCallInfo[i].eCallState = Dialtone;
  453.                   break;
  454.                     
  455.                     case LINECALLSTATE_DIALING:
  456.                         myCallInfo[i].eCallState = Dialing;
  457.                         break;
  458.                   
  459.                   case LINECALLSTATE_RINGBACK:
  460.                         myCallInfo[i].eCallState = Ringback;
  461.                         break;
  462.             
  463.                     case LINECALLSTATE_BUSY:
  464.                         myCallInfo[i].eCallState = Busy;
  465.                         break;
  466.             
  467.                     case LINECALLSTATE_SPECIALINFO:
  468.                         myCallInfo[i].eCallState = Special;
  469.                        break;
  470.             
  471.                     case LINECALLSTATE_CONNECTED:
  472.                        myCallInfo[i].eCallState = Connected;
  473.                   break;
  474.  
  475.                     case LINECALLSTATE_PROCEEDING:
  476.                         myCallInfo[i].eCallState = Proceeding;
  477.                        break;
  478.             
  479.                     case LINECALLSTATE_CONFERENCED:
  480.                         myCallInfo[i].eCallState = Conferenced;
  481.                        break;
  482.             
  483.                     case LINECALLSTATE_ONHOLDPENDCONF:
  484.                         break;
  485.                 
  486.                case LINECALLSTATE_DISCONNECTED:
  487.                         myCallInfo[i].eCallState = Disconnected;
  488.                        break;
  489.             
  490.                     case LINECALLSTATE_UNKNOWN:
  491.                         myCallInfo[i].eCallState = Unknown;
  492.                        break;
  493.        
  494.              }
  495.           }
  496.        }
  497.  
  498.        case LINE_MONITORMEDIA:
  499.            break;
  500.  
  501.        case LINE_MONITORDIGITS:
  502.           break;
  503.  
  504.          case LINE_MONITORTONE:
  505.           break;
  506.    
  507.        //error handling for functions completed asynchronously
  508.         //.....................................................
  509.        case LINE_REPLY:
  510.         {
  511.             for (i = 0; i < MAX_CALL; i++)
  512.            {
  513.                 if (dwParam1 = myCallInfo[i].dwRequestID)
  514.                {
  515.                    if (dwParam2 != 0)
  516.                    {
  517.                        lineError((LONG) dwParam2);
  518.                        break;
  519.                    }
  520.                }
  521.            }
  522.         break;
  523.         }
  524.  
  525.         case LINE_GENERATE:
  526.           break;
  527.      
  528.        case LINE_REQUEST:
  529.          break;
  530.  
  531.         case LINE_GATHERDIGITS:
  532.            break;
  533.    }
  534.  
  535.    return (TRUE);
  536.  
  537.  
  538. /****************************************************************************
  539.     FUNCTION: lineError
  540.     PURPOSE:  line error messages
  541. ****************************************************************************/
  542. void lineError (LONG lrc)
  543. {
  544.  switch (lrc) {
  545.     case LINEERR_INVALAPPHANDLE:
  546.        MessageBox (hWnd, "Invalid app handle.", "", MB_OK);
  547.        break;
  548.     case LINEERR_BADDEVICEID:
  549.        MessageBox (hWnd,"The specified line device ID is out of range.", "", 
  550.                    MB_OK);
  551.        break;
  552.     case LINEERR_INCOMPATIBLEAPIVERSION:
  553.        MessageBox (hWnd, "Incompatible API version.", "", MB_OK);
  554.        break;
  555.     
  556.     case LINEERR_ADDRESSBLOCKED:
  557.        MessageBox (hWnd, "Address was blocked.", "", MB_OK);
  558.        break;
  559.  
  560.     case LINEERR_BEARERMODEUNAVAIL:
  561.        MessageBox (hWnd, "Bearer Mode Unavailable.", "", MB_OK);
  562.        break;
  563.  
  564.     case LINEERR_CALLUNAVAIL:
  565.        MessageBox (hWnd, "Call appearances in use..", "", MB_OK);
  566.        break;
  567.  
  568.     case LINEERR_INUSE:
  569.        MessageBox (hWnd, "Line in Use.", "", MB_OK);
  570.        break;
  571.     
  572.     case LINEERR_INVALADDRESS:
  573.        MessageBox (hWnd, "Invalid Address.", "", MB_OK);
  574.        break;
  575.  
  576.     case LINEERR_INVALADDRESSID:
  577.        MessageBox (hWnd, "Invalid Address ID.", "", MB_OK);
  578.        break;
  579.  
  580.     case LINEERR_INVALCALLPARAMS:
  581.        MessageBox (hWnd, "Invalid Address ID.", "", MB_OK);
  582.        break;
  583.      
  584.     case LINEERR_INCOMPATIBLEEXTVERSION:
  585.        MessageBox (hWnd, "Incompatible extension version.","", MB_OK);
  586.        break;
  587.     case LINEERR_NOMEM:
  588.        MessageBox (hWnd, "No memory","", MB_OK);
  589.        break;
  590.     case LINEERR_NODRIVER:
  591.        MessageBox (hWnd, "No driver loaded", "", MB_OK);
  592.        break;
  593.     case LINEERR_RESOURCEUNAVAIL:
  594.        MessageBox (hWnd, "Resource overcommittment", "", MB_OK);
  595.        break;
  596.     case LINEERR_INVALPRIVSELECT:
  597.        MessageBox (hWnd, "Requested invalid priviledges", "", MB_OK);
  598.        break;
  599.     case LINEERR_INVALMEDIAMODE:
  600.        MessageBox (hWnd, "Requested invalid media mode", "", MB_OK);
  601.        break;
  602.     case LINEERR_LINEMAPPERFAILED:
  603.        MessageBox (hWnd, "Line mapper failed", "", MB_OK);
  604.        break;
  605.     case LINEERR_INVALPOINTER:
  606.        MessageBox (hWnd, "The specified pointer parameter is invalid.",
  607.                    "", MB_OK);
  608.        break;
  609.     case LINEERR_OPERATIONFAILED:
  610.        MessageBox (hWnd, "Operation failed.", "", MB_OK);
  611.        break;
  612.     case LINEERR_INVALLINEHANDLE:
  613.        MessageBox (hWnd, "Invalid line handle", "", MB_OK);
  614.        break;
  615.     case LINEERR_INVALCALLHANDLE:
  616.        MessageBox (hWnd, "Invalid call handle", "", MB_OK);
  617.        break;
  618.     case LINEERR_INVALCALLSELECT:
  619.        MessageBox (hWnd, "Invalid call selection", "", MB_OK);
  620.        break;
  621.     case LINEERR_NODEVICE:
  622.        MessageBox (hWnd, "No associated device for given class",
  623.                    "", MB_OK);
  624.        break;
  625.     case LINEERR_OPERATIONUNAVAIL:
  626.        MessageBox (hWnd, "The operation is unavailable",
  627.                    "", MB_OK);
  628.        break;
  629.     case LINEERR_INVALPARAM:
  630.         MessageBox(hWnd, "Invalid Paramater", "", MB_OK);
  631.        break; 
  632.  
  633.     case LINEERR_TARGETNOTFOUND:
  634.         MessageBox(hWnd, "Target Not Found", "", MB_OK);
  635.        break; 
  636.  
  637.    case LINEERR_NOREQUEST:
  638.       MessageBox(hWnd, "No outstanding Assisted Telephony requests.", "", MB_OK);
  639.        break; 
  640.    }
  641. }
  642.  
  643. LRESULT CALLBACK Dial ( HWND hDlg,           // window handle of the dialog box
  644.                         UINT message,        // type of message
  645.                         WPARAM wParam,       // message-specific information
  646.                         LPARAM lParam)
  647. {
  648.    switch (message) 
  649.    {
  650.        case WM_INITDIALOG:  // message: initialize dialog box
  651.                return (TRUE);
  652.  
  653.        case WM_COMMAND:                              // message: received a command
  654.          if (   LOWORD(wParam) == IDOK )        // "OK" box selected?
  655.          {
  656.             GetDlgItemText(hDlg, IDC_NAME, szName, 128);
  657.                 GetDlgItemText(hDlg, IDC_NUMBER, szNumber, 128);
  658.                                       
  659.  
  660.                 // put up a dialog box to obtain a string to dial from the user
  661.                //...........................................................
  662.                strcpy(myCallInfo[0].szDialStringOriginal, szNumber); 
  663.                
  664.                //allocate buffer for the LINEADDRESSCAPS strucuture 
  665.                //...................................................
  666.                plineTranslateOutput = (LINETRANSLATEOUTPUT *) calloc (1, sizeof(LINETRANSLATEOUTPUT)+1000);
  667.             plineTranslateOutput->dwTotalSize = sizeof(LINETRANSLATEOUTPUT) + 1000;
  668.               
  669.                // translate the Address to a dialable address and Canonical address
  670.                //.....................................................................
  671.                lRet = lineTranslateAddress(myInfo.lineApp, myLineInfo[OWNER].dwLineID, myInfo.dwAPIVersion,
  672.                                            myCallInfo[0].szDialStringOriginal, 0, 0, plineTranslateOutput);
  673.                               
  674.                if (lRet == 0)
  675.                {
  676.                        
  677.                    strncpy(myCallInfo[0].szDialString, (LPSTR)(plineTranslateOutput)
  678.                             + plineTranslateOutput->dwDialableStringOffset,
  679.                              plineTranslateOutput->dwDialableStringSize); 
  680.     
  681.                     strncpy(myCallInfo[0].szDialStringCanonical,(LPSTR)(plineTranslateOutput) 
  682.                             + plineTranslateOutput->dwDisplayableStringOffset,
  683.                             plineTranslateOutput->dwDisplayableStringSize); 
  684.                                            
  685.                    myCallInfo[0].dwTranslateResults = plineTranslateOutput->dwTranslateResults;
  686.                 }
  687.  
  688.                else 
  689.                {
  690.                     wsprintf ( buf,"lineTranslateAddress failed, err=x%lx", lRet);
  691.                     lineError(lRet);
  692.                    break;
  693.             }
  694.            
  695.                //lineMakeCall
  696.                //................................................................
  697.                           
  698.                plineCallParams = (LINECALLPARAMS *) calloc (1, sizeof(LINECALLPARAMS)+1000);
  699.             plineCallParams->dwTotalSize = sizeof(LINECALLPARAMS) + 1000;
  700.  
  701.                plineCallParams->dwBearerMode = LINEBEARERMODE_VOICE;
  702.                plineCallParams->dwMediaMode =  LINEMEDIAMODE_DATAMODEM;
  703.                plineCallParams->dwCallParamFlags = LINECALLPARAMFLAGS_IDLE;
  704.                plineCallParams->dwAddressMode    = LINEADDRESSMODE_ADDRESSID;
  705.                plineCallParams->dwAddressID    = 0;
  706.                plineCallParams->dwMinRate    = 1200;
  707.                plineCallParams->dwMaxRate    = 2400;
  708.                             
  709.                lRet = lineMakeCall(myLineInfo[OWNER].hLine,&myCallInfo[0].hCall, 
  710.                                       myCallInfo[0].szDialString ,0,  plineCallParams);
  711.            
  712.             if (lRet > 0)
  713.                {
  714.                wsprintf (buf, "lineMakeCall suceeded!");
  715.                SendMessage(hListWnd, LB_INSERTSTRING, (WPARAM) -1, (LONG) (LPSTR) buf) ;               
  716.                    myCallInfo[0].dwRequestID = lRet;
  717.                 }
  718.             else 
  719.                {
  720.                    wsprintf ( buf,"lineMakeCall failed, err=x%lx", lRet);
  721.                     lineError(lRet);
  722.                    break;
  723.             }
  724.             
  725.             EndDialog(hDlg, TRUE);        // Exit the dialog
  726.             return (TRUE);
  727.          }
  728.  
  729.             if (   LOWORD(wParam) == IDCANCEL)         // "OK" box selected?
  730.          {
  731.             EndDialog(hDlg, TRUE);        // Exit the dialog
  732.             return (TRUE);
  733.          }
  734.          break;
  735.  
  736.  
  737.    }
  738.  
  739.    return (FALSE); 
  740. }
  741.  
  742.  
  743. LRESULT CALLBACK About( HWND hDlg,           
  744.                         UINT message,        
  745.                         WPARAM wParam,       
  746.                         LPARAM lParam)
  747. {
  748.    switch (message) 
  749.    {
  750.        case WM_INITDIALOG: 
  751.                return (TRUE);
  752.  
  753.        case WM_COMMAND:                              
  754.                if (   LOWORD(wParam) == IDOK         
  755.                    || LOWORD(wParam) == IDCANCEL)    
  756.                {
  757.                        EndDialog(hDlg, TRUE);        
  758.                        return (TRUE);
  759.                }
  760.                break;
  761.    }
  762.  
  763.    return (FALSE); 
  764. }
  765.  
  766.  
  767.  
  768.